Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ExhaustiveRefasterTypeMigration check #770

Merged

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Aug 29, 2023

Suggested commit message:

Introduce `ExhaustiveRefasterTypeMigration` check (#770)

The new `@TypeMigration` annotation can be placed on Refaster rule
collections to indicate that they migrate most or all public methods of
an indicated type. The new check validates the claim made by the
annotation.

This will help flag new to-be-migrated methods any time the JUnit or TestNG dependency is upgraded. (This PR also flags that TestNGToAssertJRules is no longer nearly as exhaustive as it once was. Resolving that will be deferred to a separate PR. I started a TestNG and JUnit branch. That said, given the repetition involved, perhaps introducing a bug checker or two is in order.)

@Stephan202 Stephan202 added this to the 0.14.0 milestone Aug 29, 2023
@Stephan202 Stephan202 requested review from oxkitsune and rickie August 29, 2023 06:24
@github-actions
Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 33
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 6
🎉tech.picnic.errorprone.bugpatterns.StringJoin 0 1

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

1 similar comment
@github-actions
Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 33
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 6
🎉tech.picnic.errorprone.bugpatterns.StringJoin 0 1

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

98.7% 98.7% Coverage
0.0% 0.0% Duplication

@github-actions
Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 31
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 4
🎉tech.picnic.errorprone.bugpatterns.StringJoin 0 1

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie modified the milestones: 0.14.0, 0.15.0 Oct 4, 2023
@Stephan202 Stephan202 force-pushed the sschroevers/introduce-refaster-type-migration-annotation branch from 0da94ff to c085f2d Compare October 8, 2023 13:14
@github-actions
Copy link

github-actions bot commented Oct 8, 2023

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 31
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 4
🎉tech.picnic.errorprone.bugpatterns.StringJoin 0 1

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 8, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

98.7% 98.7% Coverage
0.0% 0.0% Duplication

@Stephan202 Stephan202 force-pushed the sschroevers/introduce-refaster-type-migration-annotation branch from c085f2d to 3cfa724 Compare December 18, 2023 16:53
Copy link

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

3 New issues
0 Security Hotspots
98.7% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 30
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 4

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

1 similar comment
Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 30
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 4

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing stands out to me 🚀

* com.google.errorprone.util.Signatures#prettyMethodSignature(com.sun.tools.javac.code.Symbol.ClassSymbol,
* com.sun.tools.javac.code.Symbol.MethodSymbol)}.
*/
String[] unmigratedMethods() default {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intellij flags this as a spelling mistake 🤔
Maybe:

Suggested change
String[] unmigratedMethods() default {};
String[] nonMigratedMethods() default {};

or

Suggested change
String[] unmigratedMethods() default {};
String[] notMigratedMethods() default {};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unmigrated is an actual word, so we can also tell IntelliJ to ignore it :). Would be my preference.

" of = Util.class,",
" unmigratedMethods = {",
" \"publicStaticVoidMethod()\",",
" \"publicStringMethodWithArg(int)\",",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to test overloaded methods here ?

Suggested change
" \"publicStringMethodWithArg(int)\",",
" \"publicStringMethodWithArg(int)\",",
" \"publicStringMethodWithArg(String)\",",

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which brings me to my question on why do we need to flag all the variants of the overloaded method ? 🤔

Is it wrong to assume that if a rule does not apply to one type set of arguments, will not be applied to other ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea to test overloads; let me add a commit for that.

As for why we should flag all variants: due to how Refaster works, each variant needs to be matched explicitly. It may be that n out of m > n overloads are covered; by explicitly listing the remainder it'll be easier to determine which rules are missing.

@Stephan202 Stephan202 force-pushed the sschroevers/introduce-refaster-type-migration-annotation branch from 3cfa724 to b969b95 Compare January 28, 2024 17:22
Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added two small commits.

" of = Util.class,",
" unmigratedMethods = {",
" \"publicStaticVoidMethod()\",",
" \"publicStringMethodWithArg(int)\",",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea to test overloads; let me add a commit for that.

As for why we should flag all variants: due to how Refaster works, each variant needs to be matched explicitly. It may be that n out of m > n overloads are covered; by explicitly listing the remainder it'll be easier to determine which rules are missing.

Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 30
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 4

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202
Copy link
Member Author

I'll rebase this branch and move the check to the new guidelines module.

@Stephan202 Stephan202 force-pushed the sschroevers/introduce-refaster-type-migration-annotation branch from b969b95 to d71244f Compare February 10, 2024 13:29
Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 30
class surviving killed
🧟tech.picnic.errorprone.guidelines.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.guidelines.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 4

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

1 similar comment
Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 30
class surviving killed
🧟tech.picnic.errorprone.guidelines.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.guidelines.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 4

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing check 🚀 !

* indicated type.
*/
// XXX: Add support for `#unmigratedFields()`.
// XXX: Consider making this annotation `@Repeatable`, for cases where a single Refaster rules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// XXX: Consider making this annotation `@Repeatable`, for cases where a single Refaster rules
// XXX: Consider making this annotation `@Repeatable`, for cases where a single Refaster rule

* com.google.errorprone.util.Signatures#prettyMethodSignature(com.sun.tools.javac.code.Symbol.ClassSymbol,
* com.sun.tools.javac.code.Symbol.MethodSymbol)}.
*/
String[] unmigratedMethods() default {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unmigrated is an actual word, so we can also tell IntelliJ to ignore it :). Would be my preference.

// XXX: Add support for `#unmigratedFields()`.
// XXX: Consider making this annotation `@Repeatable`, for cases where a single Refaster rules
// collection migrates away from multiple types.
@Target(ElementType.TYPE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure what the best sorting would be here, but we have the annotation sorting on method level. We could swap them here as well.

// XXX: Consider making this annotation `@Repeatable`, for cases where a single Refaster rules
// collection migrates away from multiple types.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Retention(RetentionPolicy.SOURCE)
@Retention(SOURCE)

Copy link
Member

@rickie rickie Feb 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don''t really lose any context with this? Do we want to add this to the StaticImport check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we don't lose much, but the current variant does seem a bit clearer to me. Since this annotation will only be present on a separate line in (almost always) small files, I don't think there's much point in forcing a static import here. Internally only 2 out of 67 usages statically import it.

" }",
" }",
"",
" // BUG: Diagnostic contains: The set of unmigrated methods listed by the `@TypeMigration`",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we simply use "// BUG: Diagnostic contains:", here? That already signals that we are just flagging this, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check emits two kinds of messages, so for each violation I'm asserting that the correct message is emitted.

@rickie rickie force-pushed the sschroevers/introduce-refaster-type-migration-annotation branch from eb7c402 to c7f03c7 Compare February 11, 2024 10:35
Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 30
class surviving killed
🧟tech.picnic.errorprone.guidelines.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.guidelines.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 4

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Stephan202 and others added 9 commits February 11, 2024 12:20
The new `@TypeMigration` annotation can be placed on Refaster rule
collections to indicate that they migrate most or all public methods of
an indicated type. The new check validates the claim made by the
annotation.
@Stephan202 Stephan202 force-pushed the sschroevers/introduce-refaster-type-migration-annotation branch from c7f03c7 to 3e54b8a Compare February 11, 2024 11:30
Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added a small commit. Will merge once built.

Comment on lines +15 to +17
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface TypeMigration {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the topic of annotation sorting: makes sense. We should extend LexicographicalAnnotationListing; will add a comment.

// XXX: Consider making this annotation `@Repeatable`, for cases where a single Refaster rules
// collection migrates away from multiple types.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we don't lose much, but the current variant does seem a bit clearer to me. Since this annotation will only be present on a separate line in (almost always) small files, I don't think there's much point in forcing a static import here. Internally only 2 out of 67 usages statically import it.

" }",
" }",
"",
" // BUG: Diagnostic contains: The set of unmigrated methods listed by the `@TypeMigration`",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check emits two kinds of messages, so for each violation I'm asserting that the correct message is emitted.

Copy link

  • Surviving mutants in this change: 7
  • Killed mutants in this change: 30
class surviving killed
🧟tech.picnic.errorprone.guidelines.bugpatterns.ExhaustiveRefasterTypeMigration 5 26
🧟tech.picnic.errorprone.guidelines.bugpatterns.ExhaustiveRefasterTypeMigration$1 2 4

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link

@Stephan202 Stephan202 merged commit 1cc792c into master Feb 11, 2024
16 checks passed
@Stephan202 Stephan202 deleted the sschroevers/introduce-refaster-type-migration-annotation branch February 11, 2024 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants